let http = require("http");
let mysql = require("mysql");

let server = http.createServer((req, res) => {
    res.setHeader('Content-Type', 'text/html; charset=utf-8')
    res.setHeader("Access-Control-Allow-Origin", "*")
    var connection = mysql.createConnection({
        host: 'localhost',
        user: 'root',
        password: 'root',
        database: 'web'
    });
    connection.connect();

    var sql = 'select * from web50';
    //查 SELECT * FROM `web50` WHERE 1
    connection.query(sql, function (err, result) {
        if (err) {
            console.log('[SELECT ERROR] - ', err.message);
            return;
        }

        console.log('--------------------------SELECT----------------------------');
        console.log(result);
        
        res.end(JSON.stringify(result))
        console.log('------------------------------------------------------------\n\n');
    });

    connection.end();

})

server.listen("3000", () => {
    console.log("3000启动");
})